home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
TPUG - Toronto PET Users Group
/
TPUG Users Group CD
/
TPUG Users Group CD.iso
/
AMIGA
/
AMICUS
/
AMICUS03.ADF
/
Xref
/
getword.c
< prev
next >
Wrap
C/C++ Source or Header
|
1986-04-02
|
2KB
|
70 lines
/**************************************************************************
NAME
getword -- gets next word from input
SYNOPSIS
l = getword(w,lim);
int l; type of object
char *w; pointer to beginning of string returned
int lim; maximum number of characters to be returned
DESCRIPTION
'word' is defined as a string of letters and digits, starting with
a letter, with a maximum of lim characters
RETURNS
l = LETTER if a word is returned
= EOF if end of file encountered
= character itself if it is not a-z or A-Z
CAUTIONS
LETTER and DIGIT must be equally defined in calling routine.
AUTHOR Philip T. Ansteth
DATE Dec. 6, 1985
CLIENT ANSTETH RESEARCH
CALLED FUNCTIONS
type -- returns type of character: letter or digit
**************************************************************************/
#define LETTER 'a'
#define DIGIT '0'
getword(w,lim) /* get next word from input */
char *w;
int lim;
{
int c,t;
/* printf("Entry to getword: lim = %d\n",lim); */
if(type(c = *w++ = getch()) != LETTER) { /* is first character non-alpha? */
*w = '\0'; /* second character of w is string terminator */
/* printf("Exit from getword: c = %c\n",c); */
return(c); /* return character in c too */
}
while (--lim > 0) { /* check subsequent characters up to lim */
t = type(c = *w++ = getch()); /* put alpha or num. in w and t */
if (t != LETTER && t != DIGIT) {
ungetch(c);
break;
}
}
*(w-1) = '\0'; /* reached end, so back up and put in string delimiter */
/* printf("Exit from getword: LETTER = %c\n",LETTER); */
return(LETTER);
}